import { createSlice } from "@reduxjs/toolkit"; //createSlice为了创建reducer和action

interface menuType {
  menuVal: any[];
}
const module = createSlice({
  name: "module",
  initialState: {
    //可以实现全局数据共享
    //数据
    tabarVal: [],//tabar的值
    //menu的值 
    menuVal: [] as menuType[],
    dygl: {}
  },
  reducers: {
    //方法
    gettabar(state, actions) {
      state.tabarVal = actions.payload;
    },
    //menu的方法
    getmenu(state, actions) {
      const path = actions.payload.key
      const label = (actions.payload.domEvent.target as HTMLInputElement).innerText
      const ls = [label, path]
      state.menuVal = ls
    },
    //删除menu的方法
    delmenu(state: any, actions: any) {
      state.menuVal = []
    },
    getshow(state, { payload }) {
      state.dygl = payload;
      // console.log(state.dygl);
    },
    setshow(state: any, { payload: { type, e } }) {
      state.dygl[type] = e;
    },
  },

});

export default module;
export const { gettabar, getmenu, delmenu, getshow, setshow } = module.actions;
